home *** CD-ROM | disk | FTP | other *** search
/ Tech Arsenal 1 / Tech Arsenal (Arsenal Computer).ISO / tek-01 / zendisk1.zip / LST7-17.ASM < prev    next >
Assembly Source File  |  1990-02-15  |  1KB  |  56 lines

  1. ;
  2. ; *** Listing 7-17 ***
  3. ;
  4. ; Performs fast, compact bit-doubling of a byte in AL
  5. ; to a word in AX by using two nibble look-ups. Overall
  6. ; code length and performance are improved by
  7. ; using base indexed addressing (bx+si) rather than base
  8. ; direct addressing (bx+DoubleNibbleTable). Even though
  9. ; an additional 3-byte MOV instruction is required to load
  10. ; SI with the offset of DoubleNibbleTable, each access to
  11. ; DoubleNibbleTable is 2 bytes shorter thanks to the
  12. ; elimination of mod-reg-rm displacements.
  13. ;
  14. ; Macro to double each bit in a byte.
  15. ;
  16. ; Input:
  17. ;    AL = byte to bit-double
  18. ;
  19. ; Output:
  20. ;    AX = bit-doubled word
  21. ;
  22. ; Registers altered: AX, BX, CL, SI
  23. ;
  24. DOUBLE_BYTE    macro
  25.     mov    bl,al    ;move the byte to look up to BL
  26.     sub    bh,bh    ; and make a word out of the value
  27.     mov    cl,4    ;make a look-up pointer out of the
  28.     shr    bx,cl    ; upper nibble of the byte
  29.     mov    si,offset DoubledNibbleTable
  30.     mov    ah,[si+bx]
  31.             ;look up the doubled upper nibble
  32.     mov    bl,al    ;get the byte to look up again,
  33.     and    bl,0fh    ; and make a pointer out of the
  34.             ; lower nibble this time
  35.     mov    al,[si+bx]
  36.             ;look up the doubled lower nibble
  37.     endm
  38. ;
  39.     jmp    Skip
  40. DOUBLED_VALUE=0
  41. DoubledNibbleTable    label    byte
  42.     db    000h, 003h, 00ch, 00fh
  43.     db    030h, 033h, 03ch, 03fh
  44.     db    0c0h, 0c3h, 0cch, 0cfh
  45.     db    0f0h, 0f3h, 0fch, 0ffh
  46. ;
  47. Skip:
  48.     call    ZTimerOn
  49. BYTE_TO_DOUBLE=0
  50.     rept    100
  51.     mov    al,BYTE_TO_DOUBLE
  52.     DOUBLE_BYTE
  53. BYTE_TO_DOUBLE=BYTE_TO_DOUBLE+1
  54.     endm
  55.     call    ZTimerOff
  56.